<template>
  <el-dialog
    title="设置发布时间"
    :visible.sync="dialogVisible"
    :before-close="cancel"
    :close-on-click-modal="false"
    class="vc-dialog-form"
    width="480px">
    <el-form ref="timingForm" :model="timingForm" :rules="rules" label-width="100px" size="small">
      <el-form-item label="发布时间" prop="time">
        <el-date-picker
          v-model="timingForm.time"
          type="datetime"
          format="yyyy-MM-dd HH:mm"
          value-format="timestamp"
          placeholder="请选择">
        </el-date-picker>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="cancel">取消</el-button>
      <el-button type="primary" size="small" @click="sure">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'scheduledRelease',
  props: ['dialogVisible', 'id'],
  data() {
    return {
      timingForm: {
        time: ''
      },
      rules: {
        time: [
          { required: true, message: '请选择发布时间', trigger: ['change', 'blur'] }
        ]
      }
    }
  },
  watch: {
    dialogVisible(val) {
      if (!val) return;
      this.$nextTick(() => {
        this.$refs.timingForm && this.$refs.timingForm.resetFields();
      });
    }
  },
  methods: {
    /**
     * 确定
     */
    sure() {
      this.$refs.timingForm.validate(valid => {
        if (!valid) {
          return false;
        }
        this.$emit('close', this.timingForm.time);
      });
    },
    /**
     * 取消
     */
    cancel() {
      this.$emit('close', false);
    }
  }
}
</script>